using UnityEngine;

namespace Player
{
    /// <summary>
    /// 玩家动画控制类
    /// </summary>
    public class PlayerAnimatorController : MonoBehaviour
    {
        //动画机组件
        private Animator animator;


        //动画参数下标
        private int move;

        private int isAiming;

        private void Awake()
        {
            animator = GetComponent<Animator>();

            Init();
        }


        private void Init()
        {
            move = Animator.StringToHash("move");
            isAiming = Animator.StringToHash("isAiming");
        }

        //播放移动动画
        public float PlayMoveAnimation(bool isSprintf, float moveMagnitude, float delta)
        {
            float v;

            //设置移动动画参数
            
            if (moveMagnitude >= 0.75f)
            {
                v = isSprintf ? 2.0f : 1.0f;
            }
            else if (moveMagnitude >= 0.01f)
            {
                v = 0.75f;
            }
            else
            {
                v = 0f;
            }
            
            animator.SetFloat(move, v, PlayerConstant.AnimationDampTime, delta);

            return v;
        }
        
        
        //播放瞄准动画
        public void PlayAimAnimation(bool isAim)
        {
            animator.SetBool(isAiming,isAim);
            
        }
    }
}